package org.linlinjava.litemall.wx.GeneratorUUIDKits;
import java.util.Random;

public class CreateUIDKit {
	/**
	 * 主函数，作为调用和测试生成验证码方法的入口
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println(GeneratorUIDTools.toSerialCode(8));
	}

	/**
	 * 生成指定长度的验证码
	 * 
	 * @author Q
	 * @param verificationCodeLength
	 * @return String
	 * @since 2016-09-6
	 */
	public static final String createVerificationCode(int verificationCodeLength) {
		// 所有候选组成验证码的字符，可以用中文
		String[] verificationCodeArrary = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e",
				"f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
				"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U",
				"V", "W", "X", "Y", "Z" };
		String verificationCode = "";
		Random random = new Random();
		// 此处是生成验证码的核心了，利用一定范围内的随机数做为验证码数组的下标，循环组成我们需要长度的验证码，做为页面输入验证、邮件、短信验证码验证都行
		for (int i = 0; i < verificationCodeLength; i++) {
			verificationCode += verificationCodeArrary[random.nextInt(verificationCodeArrary.length)];
		}
		return verificationCode;
	}

	public static int randomCode() {
		StringBuilder str = new StringBuilder();
		Random random = new Random();
		for (int i = 0; i < 6; i++) {
			str.append(random.nextInt(10));
		}
		return Integer.parseInt(str.toString());
	}

	public static int secondRandomCode() {
		return (int) ((Math.random() * 9 + 1) * 100000);
	}

	public static String getRandomCode(int number) {
		String codeNum = "";
		int[] code = new int[3];
		Random random = new Random();
		for (int i = 0; i < number; i++) {
			int num = random.nextInt(10) + 48;
			int uppercase = random.nextInt(26) + 65;
			int lowercase = random.nextInt(26) + 97;
			code[0] = num;
			code[1] = uppercase;
			code[2] = lowercase;
			codeNum += (char) code[random.nextInt(3)];
		}
		System.out.println(codeNum);

		return codeNum;
	}

	public static String getRandomNumCode(int number) {
		String codeNum = "";
		int[] numbers = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
		Random random = new Random();
		for (int i = 0; i < number; i++) {
			int next = random.nextInt(10000);// 目的是产生足够随机的数，避免产生的数字重复率高的问题
//	    			System.out.println(next);
			codeNum += numbers[next % 10];
		}
		System.out.println("--------");
		System.out.println(codeNum);

		return codeNum;
	}

}
